package com.itheima.health.controller;

import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.service.SetmealService;
import com.itheima.health.utils.resources.MessageConstant;
import com.itheima.health.vo.SetmealVO;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class WechatController {

    @Reference
    private SetmealService setmealService;

    @GetMapping("setmeal/findAll")
    public Result findSetmealAll(){
        try {
            List<Setmeal> setmealList = setmealService.list();
            return new
                    Result(true,MessageConstant.QUERY_SETMEALLIST_SUCCESS,setmealList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_SETMEALLIST_FAIL);
        }

    }

    @GetMapping("setmeal/findSetMealDetail")
    public Result findSetMealDetail(@RequestParam("id")Integer id) {
        try {
            SetmealVO setmealVO = setmealService.findSetMealDetail(id);
            return new Result(true,MessageConstant.QUERY_SETMEALLIST_SUCCESS,setmealVO);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_SETMEALLIST_FAIL);
        }

    }

    @GetMapping("setmeal/findById")
    public Result findById(@RequestParam("id")Integer id) {
        try {
            Setmeal setmeal = setmealService.findById(id);
            return new Result(true,MessageConstant.QUERY_SETMEALLIST_SUCCESS,setmeal);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_SETMEALLIST_FAIL);
        }

    }
}
